//
//  KAExitReasonHeader.swift
//  kano
//
//  Created by Frank on 2025/5/15.
//

import UIKit

class KAExitReasonHeader: UITableViewHeaderFooterView {
    
    let titleLabel = UILabel()
    let icon = UIImageView()
    
    var isSelectedHeader: Bool = false {
        didSet {
            icon.image = isSelectedHeader ? UIImage(named: "checkCircle_sel") : UIImage(named: "checkCircle_unsel")
        }
    }
    
    var tapAction: (() -> Void)?
    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        setupViews()
        let tap = UITapGestureRecognizer(target: self, action: #selector(handleTap))
        contentView.addGestureRecognizer(tap)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupViews() {
        contentView.backgroundColor = .white
        contentView.addSubview(icon)
        contentView.addSubview(titleLabel)
        
        icon.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(kscale(16))
            make.width.height.equalTo(kscale(16))
        }
        
        titleLabel.snp.makeConstraints { make in
            make.top.equalTo(icon)
            make.left.equalTo(icon.snp.right).offset(kscale(10))
            make.right.equalToSuperview().offset(kscale(-10))
        }
        
        titleLabel.numberOfLines = 1
        titleLabel.font = .systemFont(ofSize: kscale(14))
        titleLabel.textColor = UIColor.ka_hexColor(0x30323E)
    }
    
    @objc private func handleTap() {
        tapAction?()
    }
    
}
